<div style="margin: 5px;">
    <div class="layui-btn-group userTable">
        <button class="layui-btn" data-type="addSort">添加会员</button>
    </div>
    <table id="user-table" lay-filter="user-table-filter"></table>
</div>

<script type="text/html" id="userBar">
    <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
    <a class="layui-btn  layui-btn-xs" lay-event="edit">修改</a>
</script>
<script type="text/html" id="user-header-tpl">
        <img height="100%" width="100%" src="{{d.user_img}}" class="layui-nav-img">
</script>

<script>
    layui.use(['table', 'form'], function () {
        var table = layui.table;
        //-------会员管理表格s--------
        var user = table.render({
            elem: '#user-table'
            , height: 'full-180'
            , url: '/admin/usermanagement/ajax'
            , page: true
            , cols: [[
                {field: 'user_id', title: 'ID',align:'center'}
                , {field: 'user_name', title: '用户名',align:'center'}
                , {field: 'user_nick', title: '用户昵称',align:'center'}
                , {field: 'user_img', title: '用户头像',align:'center',templet:"#user-header-tpl"}
                , {field: 'user_type', title: '用户类别',align:'center'}
                , {field: '', title: '操作', toolbar: '#userBar',align:'center'}
            ]]
        });
        table.on('tool(user-table-filter)', function (obj) {
            let data = obj.data;
            if (obj.event == 'del') {
                if (obj.data.user_id === 1) {
                    layer.alert('管理员不允许删除');
                    return false;
                }
                layer.confirm('是否要删除' + data.user_name + '这个用户', function (index) {
                    $.ajax({
                        type: 'post'
                        , url: '/admin/usermanagement/dell'
                        , dataType: 'json'
                        , data: {user_id: data.user_id}
                        , success: function (obj1) {
                            if (obj1.code == 1) {
                                obj.del();
                            }
                            layer.alert(obj1.msg);
                        }
                    });
                    layer.close(index);
                });
            } else if (obj.event == 'edit') {
                layer.open({
                    type: 2 //Page层类型
                    , area: ['550px', '600px']
                    , title: '修改会员'
                    , shade: 0.6 //遮罩透明度
                    , maxmin: true //允许全屏最小化
                    , anim: 1 //0-6的动画形式，-1不开启
                    , content: '/admin/usermanagement/edit?user_id=' + data.user_id
                    , end: function () {
                        user.reload('user-table');

                    }
                });
            }
        });
        var $ = layui.$, active = {
            addSort: function () { //获取选中数据
                layer.open({
                    type: 2 //Page层类型
                    , area: ['550px', '600px']
                    , title: '添加会员'
                    , shade: 0.6 //遮罩透明度
                    , maxmin: true //允许全屏最小化
                    , anim: 1 //0-6的动画形式，-1不开启
                    , content: '/admin/usermanagement/adduser'
                    , end: function () {
                        user.reload('user-table');

                    }
                });
            }
        };
        $('.userTable .layui-btn').on('click', function () {
            var type = $(this).data('type');
            active[type] ? active[type].call(this) : '';
        });
        //-------会员管理表格e--------



    });
</script>

